#!/usr/bin/env ruby -w
#--
# Project:      pkgman
# File:         test/test_pkgman.rb
# Revision:     $Id: test_pkgman.rb 192 2007-11-21 04:16:08Z someword $
# Home:         http://code.google.com/p/pkgman/
# Author:       Derek Olsen <someword at gmail dot com>
# Copyright:    (c) 2007 by Derek Olsen
# License:      GNU General Public License v2 
#++
remove_pkgs = ["ZZZpkgman-remove-y0", 
"ZZZpkgman-remove-y1", "ZZZpkgman-remove-y2",
"ZZZpkgman-remove-y3", "ZZZpkgman-remove-y4", "ZZZpkgman-remove-y5",
"ZZZpkgman-remove-y6", "ZZZpkgman-remove-y7", "ZZZpkgman-remove-y8",
"ZZZpkgman-remove-y9", "ZZZpkgman-remove-z0", "ZZZpkgman-remove-z1",
"ZZZpkgman-remove-z2", "ZZZpkgman-remove-z3", "ZZZpkgman-remove-z4",
"ZZZpkgman-remove-z5", "ZZZpkgman-remove-z6", "ZZZpkgman-remove-z7",
"ZZZpkgman-remove-z8", "ZZZpkgman-remove-z9"]

install_pkgs = ["ZZZpkgman-install-a0",
"ZZZpkgman-install-a1", "ZZZpkgman-install-a2",
"ZZZpkgman-install-a3", "ZZZpkgman-install-a4", "ZZZpkgman-install-a5",
"ZZZpkgman-install-a6", "ZZZpkgman-install-a7", "ZZZpkgman-install-a8",
"ZZZpkgman-install-a9", "ZZZpkgman-install-b0", "ZZZpkgman-install-b1",
"ZZZpkgman-install-b2", "ZZZpkgman-install-b3", "ZZZpkgman-install-b4",
"ZZZpkgman-install-b5", "ZZZpkgman-install-b6", "ZZZpkgman-install-b7",
"ZZZpkgman-install-b8", "ZZZpkgman-install-b9"]

  def installed(n)
    system "pkginfo -q #{n}"
  end

# Make sure none of the pkgs we are going to install are already installed
install_pkgs.each do |p|
  if installed(p)
    system "/usr/bin/pfexec pkgrm -n -a ./admin #{p}"
  end
end

# Make sure the pgks we are going to remove are installed
remove_pkgs.each do |p|
  if !installed(p)
    system "/usr/bin/pfexec pkgadd -n -a `pwd`/admin -d ./pkgs/#{p} all"
  end
end
